package cn.name.ssmbase.service.impl;

import cn.name.ssmbase.domain.*;
import cn.name.ssmbase.mapper.AreaMapper;
import cn.name.ssmbase.mapper.CityMapper;
import cn.name.ssmbase.mapper.ProvinceMapper;
import cn.name.ssmbase.service.AreaService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Nominal on 2018/1/25 0025.
 * 微博：@Mr丶Li_Anonym
 */
@Service
public class AreaServiceImpl implements AreaService {
    private static Logger logger = Logger.getLogger(AreaServiceImpl.class);
    @Autowired
    AreaMapper areaMapper;
    @Autowired
    CityMapper cityMapper;
    @Autowired
    ProvinceMapper provinceMapper;
    @Autowired
    ProvinceExample provinceExample;
    @Autowired
    AreaExample areaExample;
    @Autowired
    CityExample cityExample;
    /**
     * 查询省份
     *
     * @return
     */
    public List<Province> findProvince() {
        List<Province> list=provinceMapper.selectByExample(provinceExample);
        for (Province province : list) {
            System.out.println(province);
        }
        return list;
    }

    /**
     * 查询市 根据省份
     *
     * @param province
     * @return
     */
    public List<City> findCity(Province province) {
        System.out.println(province.getCodeP()+"ddd");
        cityExample.createCriteria().andCodePEqualTo(province.getCodeP());
        List<City> list=cityMapper.selectByExample(cityExample);
        cityExample.clear();
        for (City city : list) {
            System.out.println(city);
        }
        return list;
    }

    /**
     * 查询区县 根据市
     *
     * @param city
     * @return
     */
    public List<Area> findArea(City city) {
        System.out.println(city.getCodeC()+"cccc");
        areaExample.createCriteria().andCodeCEqualTo(city.getCodeC());
        List<Area> list=areaMapper.selectByExample(areaExample);
        areaExample.clear();
        for (Area area : list) {
            System.out.println(area);
        }
        return list;
    }

}
